package com.feizhi.inventory.fragment.inventorysheet;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.feizhi.inventory.bean.InventoryBean;
import com.feizhi.inventory.databinding.ItemInventoryBinding;

import java.util.List;

/**
 *  盘点单号适配器
 * */
public class InventorySheetAdapter extends RecyclerView.Adapter<InventorySheetAdapter.InventoryViewHolder> {

    private List<InventoryBean> data;
    private ItemOnClickListener listener;

    public InventorySheetAdapter(List<InventoryBean> data) {
        this.data = data;
    }

    @Override
    public InventorySheetAdapter.InventoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemInventoryBinding mBinding = ItemInventoryBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new InventoryViewHolder(mBinding);
    }

    @Override
    public void onBindViewHolder(InventorySheetAdapter.InventoryViewHolder holder, int position) {

//        holder.mBinding.inventoryNumber.setText(data.get(position).getInventory_number());
        holder.mBinding.count.setText(data.get(position).getCount());
        holder.mBinding.createDate.setText(data.get(position).getCreate_date());
        holder.mBinding.inventoryDate.setText(data.get(position).getInventory_date());
//        holder.mBinding.incomplete.setImageResource(data.get(position).getImage());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.ItemOnClickListener(position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return data == null? 0 : data.size();
    }

    public class InventoryViewHolder extends RecyclerView.ViewHolder {

         private ItemInventoryBinding mBinding;

        public InventoryViewHolder(ItemInventoryBinding mBinding) {
            super(mBinding.getRoot());
            this.mBinding = mBinding;
        }
    }

    public void setItemOnClickListener(ItemOnClickListener listener) {
        this.listener = listener;
    }

    //写一个点击方法的接口
    public interface ItemOnClickListener {
        void ItemOnClickListener(int position);
    }
}
